package com.behavior.chainOfResponsibility;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 审核规定；
 * 1. 601-610 三级审批 + 二级审批
 * 2. 611-620 三级审批 + 二级审批 + 一级审批
 * 3. 其他时间 三级审批
 *
 * @author xiaobing
 * @version 1.0
 * @date 2021/9/22 1:52 下午
 */
public abstract class AuthLink {
    private Logger logger = LoggerFactory.getLogger(AuthLink.class);


    protected SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    /**
     * 用户id
     */
    protected String levelUserId;

    /**
     * 姓名
     */
    protected String levelUserName;

    private AuthLink next;

    public AuthLink(String levelUserId, String levelUserName) {
        this.levelUserId = levelUserId;
        this.levelUserName = levelUserName;
    }

    public AuthLink getNext() {
        return next;
    }

    public AuthLink appendNext(AuthLink link) {
        this.next = link;
        return this;
    }

    public AuthInfo handler(String uId, String orderId, Date authDate){
        Date date = AuthService.queryAuthInfo(levelUserId, orderId);
        if (date == null){
           return doAuth(uId,orderId,authDate);
        }
        AuthLink next = getNext();
        return next.handler(uId,orderId,authDate);
    }

    public abstract AuthInfo doAuth(String uId, String orderId, Date authDate);
}
